package com.itlong.cloud.app.resource;

import com.itlong.cloud.POJO.DTO.app.AppGetProjectDTO;
import com.itlong.cloud.POJO.DTO.app.AppTouristDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.app.AppDistinctProjectVO;
import com.itlong.cloud.POJO.VO.app.AppGetProjectUiVO;
import com.itlong.cloud.POJO.VO.app.AppProjectBuildVO;
import com.itlong.cloud.POJO.VO.app.AppProjectRoomVO;
import com.itlong.cloud.POJO.VO.property.PropertyProjectBuildSimpleInfoVO;
import com.itlong.cloud.POJO.VO.property.PropertyProjectRoomInfoVO;
import com.itlong.cloud.POJO.VO.property.PropertyProjectRoomSimpleInfoVO;
import com.itlong.cloud.POJO.VO.property.PropertyProjectUnitSimpleInfoVO;
import com.itlong.cloud.app.service.IAppProjectService;
import com.itlong.cloud.project.app.IAppProjectServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 *<desc>
 *     新版APP的项目信息接口代理实现类
 *</desc>
 *
 * @createDate 2017/9/29
 */
@RestController
public class AppProjectServiceResource implements IAppProjectServiceClient {

    @Autowired
    IAppProjectService iAppProjectService;

    /**
     * <desc>
     *      根据城市名称获取城市id
     * </desc>
     *
     * @param cityName
     * @return
     * @author Jiaqi.X
     * @createDate 2020/05/28
     */
    @RequestMapping(path = "/home/getCityIdByCityName",method = RequestMethod.POST)
    public String getCityIdByCityName(@RequestParam("cityName") String cityName){
        return iAppProjectService.getCityIdByCityName(cityName);
    }

    /**
     * <desc>
     *     根据城市ID获取启用状态的项目信息（项目编号与项目名称）
     * </desc>
     *
     * @param appGetProjectDTO app获取项目信息传参DTO
     * @return
     * @author cuiduanwu
     * @throws Exception
     * @createDate 2017/9/29
     */
    @Override
    @RequestMapping(path = "/home/getProjectsInCity",method = RequestMethod.POST)
    public List<AppDistinctProjectVO> getProjectsInCity(@RequestBody AppGetProjectDTO appGetProjectDTO) throws Exception{
        return iAppProjectService.getProjectsInCity(appGetProjectDTO);
    }

    /**
     * <desc>
     *     app2.0根据城市ID获取启用状态的项目信息（项目编号与项目名称）
     * </desc>
     *
     * @param cityId 城市ID
     * @return
     * @author Qiang.S
     * @throws Exception
     * @createDate 2019/06/20
     */
    @Override
    @RequestMapping(path = "/home/getNewProjectsInCity",method = RequestMethod.POST)
    public List<AppProjectBuildVO> getNewProjectsInCity(@RequestParam("cityId") String cityId) throws Exception{
        return iAppProjectService.getNewProjectsInCity(cityId);
    }

    /**
     * <desc>
     *     app2.0根据楼栋编号获取单元和房间
     * </desc>
     *
     * @param buildId 楼栋编号
     * @return
     * @author Qiang.S
     * @throws Exception
     * @createDate 2019/06/20
     */
    @Override
    @RequestMapping(path = "/home/getNewProjectsUnit",method = RequestMethod.POST)
    public List<AppProjectRoomVO> getNewProjectsUnit(@RequestParam("buildId") String buildId) throws Exception{
        return iAppProjectService.getNewProjectsUnit(buildId);
    }

    /**
     * <desc>
     *     根据国家ID获取启用状态的项目信息（项目编号与项目名称）
     * </desc>
     *
     * @param countryId 国家ID
     * @param pageNo
     * @param pageSize
     * @return
     * @author shengen.T
     * @throws Exception
     * @createDate 2017/9/29
     */
    @RequestMapping(path = "/home/getProjectsInCountry",method = RequestMethod.POST)
    public Page<Map<String,Object>> getProjectsInCountry(
            @RequestParam("countryId") String countryId,
            @RequestParam("pageNo") String pageNo,
            @RequestParam("pageSize") String pageSize) throws  Exception{
        return iAppProjectService.getProjectsInCountry(countryId,pageNo,pageSize);
    }


    /**
     * <desc>
     *     根据项目编号获取启用状态的楼栋信息
     * </desc>
     *
     * @param projectId  项目编号
     * @param pageNo
     * @param pageSize
     * @return
     * @author cuiduanwu
     * @throws Exception
     * @createDate 2017/9/29
     */
    @Override
    @RequestMapping(path = "/home/getBuildList",method = RequestMethod.POST)
    public Page<PropertyProjectBuildSimpleInfoVO> getBuildsInProject(
            @RequestParam("projectId") String projectId,
            @RequestParam("pageNo") String pageNo,
            @RequestParam("pageSize") String pageSize) throws  Exception{

            return  iAppProjectService.getBuildsInProject(projectId,pageNo,pageSize);
    }


    /**
     * <desc>
     *      根据楼栋ID获取启用状态的单元信息
     * </desc>
     * @param buildId  楼栋ID
     * @return
     * @throws Exception
     * @createDate 2017/9/30
     *  @author cuiduanwu
     */
    @Override
    @RequestMapping(path = "/home/getUnitList",method = RequestMethod.POST)
    public Page<PropertyProjectUnitSimpleInfoVO> getUnitsInBuild(
            @RequestParam("buildId") String buildId) throws  Exception{
        return  iAppProjectService.getUnitsInBuild(buildId);
    }

    /**
     * <desc>
     *      根据单元ID获取启用状态的房间信息
     * </desc>
     * @param unitId  单元ID
     * @param pageNo
     * @param pageSize
     * @return
     * @throws Exception
     * @createDate 2017/10/9
     * @author cuiduanwu
     */
    @Override
    @RequestMapping(path = "/home/getRoomList",method = RequestMethod.POST)
    public Page<PropertyProjectRoomSimpleInfoVO> getRoomsInUnit(
            @RequestParam("unitId") String unitId,
            @RequestParam("pageNo") String pageNo,
            @RequestParam("pageSize") String pageSize) throws  Exception{
        return  iAppProjectService.getRoomsInUnit(unitId, pageNo, pageSize);
    }

    /**
     * <desc>
     *      根据房间ID获取房间信息
     * </desc>
     * @param roomId  房间ID
     * @return
     * @throws Exception
     * @createDate 2017/10/23
     * @author cuiduanwu
     */
    @Override
    @RequestMapping(path = "/home/getRoomById",method = RequestMethod.POST)
    public PropertyProjectRoomInfoVO getRoomById(@RequestParam("roomId") String roomId){
        return  iAppProjectService.getRoomById(roomId);
    }

    /**
     * <desc>
     *      根据用户id获取该用户id下所有项目id集合 多个,号分隔
     * </desc>
     * @param userId 用户id
     * @return
     */
    @RequestMapping(path = "/home/getUserProjectIds")
    @Override
    public String getUserProjectIds(@RequestParam("userId")String userId) {
        return iAppProjectService.getUserProjectIds(userId);
    }

    /**
     * <desc>
     *      设置APP是否被呼叫
     * </desc>
     *
     * @param userId 用户id
     * @param isAllowApp app是否允许被呼叫 0是 1否
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/13
     */
    @RequestMapping(path = "/home/setAllowApp")
    @Override
    public Integer setAllowApp(@RequestParam("userId") String userId,
                               @RequestParam("isAllowApp") Integer isAllowApp,
                               @RequestParam(value = "projectId",required = false) String projectId) {
        return iAppProjectService.setAllowApp(userId,isAllowApp,projectId);
    }

    /**
     * <desc>
     *      设置电话是否被呼叫
     * </desc>
     *
     * @param projectId 项目id
     * @param userId 用户id
     * @param isAllowPhone 是否允许被呼叫 0是 1否
     * @return
     */
    @RequestMapping(path = "/home/setAllowPhone")
    @Override
    public Integer setAllowPhone(@RequestParam("projectId") String projectId,
                                 @RequestParam("userId") String userId,
                                 @RequestParam("isAllowPhone") String isAllowPhone){
        return iAppProjectService.setAllowPhone(projectId,userId,isAllowPhone);
    }

    /**
     * <desc>
     *      设置app登录用户当前项目id
     * </desc>
     *
     * @param userId 用户id
     * @param projectId 项目id
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/28
     */
    @RequestMapping(path="/home/setCurrentProject")
    @Override
    public Integer setCurrentProject(@RequestParam("userId") String userId,
                              @RequestParam("projectId") String projectId,
                              @RequestParam("projectName") String projectName){
        return iAppProjectService.setCurrentProject(userId,projectId,projectName);
    }

    /**
     * <desc>
     *      获取用户所有的项目id
     * </desc>
     *
     * @param userId 用户id
     * @return
     * @author Jiaqi.X
     * @createDate 2017/12/21
     */
    @RequestMapping(path = "/home/getAllProjects")
    @Override
    public List<String> getAllProjects(@RequestParam("userId") String userId){
        return iAppProjectService.getAllProjects(userId);
    }

    /**
     * <desc>
     *      获取当前用户下所有项目的UI信息
     * </desc>
     *
     * @param projectIds 多个项目编号id，中间以逗号隔开
     * @return
     * @author JuGuang.S
     * @createDate 2018/05/24
     */
    @RequestMapping(path = "/home/getProjectIdUi")
    @Override
    public List<AppGetProjectUiVO> getProjectIdUi(String projectIds, String deviceType) {
        return iAppProjectService.getProjectIdUi(projectIds,deviceType);
    }

    /**
     * <desc>
     *      获取用户当前项目下的推送消息
     * </desc>
     *
     * @return 当前项目下的推送消息
     * @createDate 2019/05/30
     * @author wangzhi
     */
    @Override
    @RequestMapping(path = "/home/getMessageBox")
    public Map<String, Object> getMessageBox(@RequestParam("projectId") String projectId, @RequestParam("pageNum") String pageNum,
                                             @RequestParam("msgType") String msgType, @RequestParam("userId") String userId, @RequestParam("url") String url,
                                             @RequestParam(value = "version", required = false) String version) throws Exception {
        return iAppProjectService.getMessageBox(projectId, pageNum, msgType, userId, url, version);
    }

    /**
     * <desc>
     *      用户读取新消息
     * </desc>
     *
     * @param msgId 消息id
     * @return 1读取成功，0失败
     * @createDate 2019/05/30
     * @author wangzhi
     */
    @Override
    @RequestMapping(path = "/home/readNewMsg")
    public Integer readNewMsg(@RequestParam("msgId") String msgId, @RequestParam("userId") String userId) throws Exception {
        return iAppProjectService.readNewMsg(msgId, userId);
    }

    /**
     * <desc>
     *      上传常用楼层
     * </desc>
     *
     * @param projectId       项目编号
     * @param deviceUnique    设备序列号
     * @param loadDeviceOrder 常用楼层名称
     * @param userId 用户id
     * @return 1成功，0失败
     * @author wangzhi
     * @createDate 2019/10/08
     */
    @Override
    @RequestMapping(path = "/home/uploadChoiceFloor")
    public Integer uploadChoiceFloor(@RequestParam("projectId") String projectId, @RequestParam("deviceUnique") String deviceUnique,
                                     @RequestParam("loadDeviceOrder") String loadDeviceOrder, @RequestParam("userId") String userId,
                                     @RequestParam(value = "loadPublicOrder",required = false) String loadPublicOrder    ) throws Exception {
        return iAppProjectService.uploadChoiceFloor(projectId, deviceUnique, loadDeviceOrder, userId,loadPublicOrder);
    }

    /**
     * <desc>
     *      自动切换小区
     * </desc>
     *
     * @param longitude 经度
     * @param latitude  纬度
     * @param userId    用户id
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/10/11
     */
    @Override
    @RequestMapping(path = "/home/autoMatchProject")
    public Map<String, Object> autoMatchProject(@RequestParam("longitude") String longitude, @RequestParam("latitude") String latitude, @RequestParam("userId") String userId) throws Exception {
        return iAppProjectService.autoMatchProject(longitude, latitude, userId);
    }

    /**
     * <desc>
     *      获取用户当前项目下的推送消息包括运营+物业
     * </desc>
     *
     * @return 当前项目下的推送消息
     * @author JuGuang.S
     * @createDate 2018/09/17
     */
    @RequestMapping(path = "/home/getMessageBoxByPropertyAndOperate")
    public Map<String, Object> getMessageBoxByPropertyAndOperate(@RequestParam("projectId") String projectId,
                                                                 @RequestParam("pageNum") String pageNum,
                                                                @RequestParam("userId") String userId,
                                                                 @RequestParam("url") String url) throws Exception {
        return iAppProjectService.getMessageBoxByPropertyAndOperate(projectId, pageNum, userId, url);
    }

    /**
     * <desc>
     *      检测项目是否开启蓝牙进场呼梯配置
     * </desc>
     *
     * @param projectId
     * @return
     * @author Jiaqi.X
     * @createDate 2020/04/27
     */
    @RequestMapping(path = "/home/checkProjectBlueToothCall")
    public Integer checkProjectBlueToothCall(@RequestParam("projectId") String projectId){
        return iAppProjectService.checkProjectBlueToothCall(projectId);
    }

    /**
     * <desc>
     *      根据定位获取最近的开通了游客模式的项目
     * </desc>
     *
     * @return 项目信息
     * @author wangzhi
     * @createDate 2020/04/30
     */
    @Override
    @RequestMapping(path = "/home/getProjectByLocation")
    public Map<String, Object> getProjectByLocation(@RequestBody AppTouristDTO appTouristDTO) throws Exception {
        return iAppProjectService.getProjectByLocation(appTouristDTO);
    }

    /**
     * <desc>
     *      获取项目远程开门配置
     * </desc>
     *
     * @param projectId
     * @return
     * @author Juguang.S
     * @createDate 2020/09/17
     */
    @Override
    @RequestMapping(path = "/home/getNetworkOpenSetting")
    public Integer getNetworkOpenSetting(@RequestParam("projectId") String projectId){
        return iAppProjectService.getNetworkOpenSetting(projectId);
    }

    /**
     * <desc>
     *      保存用户项目信息
     * </desc>
     *
     * @param appGetProjectDTO 选择项目参数DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/6
     */
    @Override
    @PostMapping("/home/saveUserProject")
    public Integer saveUserProject(@RequestBody AppGetProjectDTO appGetProjectDTO) throws Exception {
        return iAppProjectService.saveUserProject(appGetProjectDTO);
    }

    /**
     * <desc>
     *      模糊查询项目
     * </desc>
     *
     * @param projectName 项目名称
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/6
     */
    @Override
    @PostMapping("/home/getProjectByProjectName")
    public List<Map<String, Object>> getProjectByProjectName(@RequestParam(value = "projectName", required = false) String projectName) throws Exception {
        return iAppProjectService.getProjectByProjectName(projectName);
    }

    /**
     * <desc>
     *      删除用户项目
     * </desc>
     *
     * @param appGetProjectDTO 删除用户项目信息参数DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/7
     */
    @Override
    @PostMapping("/home/deleteUserProject")
    public MessageVO deleteUserProject(@RequestBody AppGetProjectDTO appGetProjectDTO) throws Exception {
        return iAppProjectService.deleteUserProject(appGetProjectDTO);
    }

    /**
     * <desc>
     *      获取项目下的用户类型id和用户类型名称
     * </desc>
     *
     * @param roomId 房间id
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/17
     */
    @Override
    @PostMapping("/home/getProjectRoleList")
    public List<Map<String, Object>> getProjectRoleList(@RequestParam("roomId") String roomId) throws Exception {
        return iAppProjectService.getProjectRoleList(roomId);
    }

    /**
     * <desc>
     *      获取项目下的用户类型id和用户类型名称
     * </desc>
     *
     * @param projectId 项目id
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/17
     */
    @Override
    @PostMapping("/home/getProjectUserRoleList")
    public List<Map<String, Object>> getProjectUserRoleList(@RequestParam("projectId") String projectId) throws Exception {
        return iAppProjectService.getProjectUserRoleList(projectId);
    }

    /**
     * <desc>
     *      获取项目下的用户类型id和用户类型名称
     * </desc>
     *
     * @param projectId 项目id
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/17
     */
    @PostMapping("/property/getProjectRoleListByProjectId")
    @Override
    public List<Map<String, Object>> getProjectRoleListByProjectId(@RequestParam("projectId") String projectId) throws Exception {
        return iAppProjectService.getProjectRoleListByProjectId(projectId);
    }
}
